#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

void getWindow(int a[], int sizeA, int b[], int sizeB)
{
    vector<vector<int> > dp(sizeA+1, vector<int>(sizeB+1, 0));
    
    for (int i = 1; i <= sizeB; i++)
        dp[0][i] = sizeA + 1;


    for (int i = 0; i <= sizeA; i++) {
        for (int j = 0; j <= sizeB; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    for (int i = 1; i <= sizeA; i++) {
        for (int j = 1; j <= sizeB; j++) {
            if (a[i-1] == b[j-1]) {
                dp[i][j] = 1 + dp[i-1][j-1];
            } else {
                dp[i][j] = 1 + dp[i-1][j];
            }
        }
    }

    int min = sizeA+1;
    int start = 0;

    for (int i = 0; i <= sizeA; i++) {
        for (int j = 0; j <= sizeB; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    for (int i = 1; i <= sizeA; i++) {
        if (dp[i][sizeB] < min) {
            min = dp[i][sizeB];
            start = i - min;        
        }
    }
    cout << endl << endl;

    for (int i = start; i < start + min; i++)
        cout << a[i] << " ";
    
    cout << endl;
}


int main(int argc, char **argv)
{

    cout << "-----------------Test 1--------------------" << endl;
    int a[] = {9,3,3,21,12,21,9,3,4,512,6,7,21} ;
    int b[] = {9,12,21};
    getWindow(a, sizeof(a)/sizeof(int), b, sizeof(b)/sizeof(int));


    cout << "-----------------Test 2--------------------" << endl;
    int a1[] = {9,9,2,1,3,4,9,2,0,3,4,5,6} ;
    int b1[] = {2,3,4};

    getWindow(a1, sizeof(a1)/sizeof(int), b1, sizeof(b1)/sizeof(int));


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
